package demo2;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 石方旭
 * Date: 2022-07-29
 * Time: 11:05
 */
public class TestDemo {


    public static Object locker1 = new Object();
    public static Object locker2 = new Object();
    //对不同的锁对象加锁
    public static void main(String[] args) {

        Thread t1 = new Thread(()->{
            synchronized(locker1){
                System.out.println("t1 - > start");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("t1 - > end");
            }
        });
        t1.start();

        Thread t2 = new Thread(()->{
            synchronized(locker1){
                System.out.println("t2 - > start");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("t2 - > end");
            }
        });
        t2.start();

    }


}
